@humany/widget-core
Core components for the Humany widget framework.
Humany
The Humany runtime object is the main object in the widget framework and is used to create and setup implementations, as well as providing methods for accessing implementations and widgets in the runtime.
Humany.create(): Humany
(static)
Creates a new Humany
instance using default settings.
Humany.createFromGlobal(globalHumany: any): Humany
(static)
Creates a new Humany
instance from a global object which can be either a temporary object created by the Humany embed script or an existing Humany
instance. This factory method is used to support eager runtime configurations in a setup when the Humany
runtime is loaded asynchronously.
humany.widgets.find(selector: WidgetSelector): WidgetData
Returns the first widget that matches the provided selector.
humany.widgets.query(selector: WidgetSelector): WidgetData[]
Returns all widgets that matches the provided selector.
humany.widgets.all(): WidgetData[]
Returns all widgets in the the runtime.
humany.implementations.find(selector: ImplementationSelector): Implementation
Returns the first implementation that matches the provided selector.
humany.implementations.query(selector: ImplementationSelector): Implementation[]
Returns all implementations that matches the provided selector.
humany.implementations.all(): Implementation[]
Returns all implementations in the the runtime.
Widget
Base class for Humany widgets.
Plugin
Base class for Humany plugins.
loadImplementation(humany: Humany, url: string): Promise<Implementation>
Loads an implementation configuration from the Humany service and creates an instance of the implementation on the provided Humany
object.
bootstrap(implementation: Implementation, (config: Configurator) => void): Promise
Bootstraps the provided implementation by scanning the document for trigger elements associated to the widgets in the implementation.
Example
The following example sets up a remote Humany implementation containing a Floating
widget and bootstraps it using the default bootstrapping extensions (with support for "trigger elements").
import { Humany, loadImplementation, bootstrap } from '@humany/widget-core';
import { FloatingWidget } from '@humany/widget-types-floating';
(async () => {
const humany = window.humany = Humany.createFromGlobal(window.humany);
const implementation = await loadImplementation(
humany,
'https://sandbox.humany.net/floating-demo',
);
bootstrap(implementation, (config) => {
config.types.register('@humany/floating-widget', FloatingWidget);
config.ready(() => console.info('Implementation has been bootstrapped'));
});
})();